package com.FH.applyFrom.vacationForm;

import com.FH.util.ResultDTO;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by Administrator on 2016/7/14.
 * 休假申请单资源类
 */


@Path("/vacationForm")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class VacationFormResource {

    @EJB
    private  VacationFormDAO vacationFormDAO;

    /**
     * 按条件查询休假申请单
     * @param search
     * @param page
     * @param size
     * @return
     */
    @GET
    @Path("/{search}&{page}&{size}")
    public ResultDTO getVacationFormInfo(@PathParam("search") String search, @PathParam("page") String page, @PathParam("size") String size){
        //添加分页查询
        if(null==page||"".equals(page)||"0".equals(page))
        {
            page = "1";	//默认从第1页开始查起
        }
        if(null==size||"".equals(size))
        {
            size = "10";//默认10行数据
        }
        return vacationFormDAO.getVacationFormInfo(search, page, size);
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addVacationFormInfo(VacationFormPullDTO vacationFormPullDTO){
        return vacationFormDAO.addVacationFormInfo(vacationFormPullDTO);
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteVacationFormInfo(VacationFormPullDTO vacationFormPullDTO){
        return vacationFormDAO.deleteVacationFormInfo(vacationFormPullDTO);
    }

    @PUT
    @Path("/update")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateVacationFormInfo(VacationFormPullDTO vacationFormPullDTO){
        return vacationFormDAO.updateVacationFormInfo(vacationFormPullDTO);
    }
}
